﻿using System;
using Needle.Framework;
using Needle.Utils.Extensions;
using Needle.DevToolkit.Services;
using Needle.DevToolkit.Services.UI;
using SCM = System.ComponentModel;
using SCMD = System.ComponentModel.Design;

namespace Needle.DevToolkit
{
    public partial class ToolKit : Container 
    {

        public ToolKit()
        {
            SCMD.IServiceContainer services = this.GetService<SCMD.IServiceContainer>();
            services.AddService<SCM.IContainer>(this);
            services.AddService<SCMD.ISelectionService>(OnCreateService);
            services.AddService<IComponentLoader>(OnCreateService);
            services.AddService<ICommandService>(OnCreateService);
        }

        private object OnCreateService(SCMD.IServiceContainer container, Type serviceType)
        {
            if (serviceType == typeof(SCMD.ISelectionService))
                return new SelectionService(container);

            if (serviceType == typeof(IComponentLoader))
                return new ComponentLoader(container);

            if (serviceType == typeof(ICommandService))
                return new CommandService(container);

            return null;
        }
    }
}
